package laborhazi;

import javax.swing.JFrame;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.WindowConstants;


public class ShowScore extends JFrame {
	
	private JPanel myPanel = null;
	private final int WIDTH = 300, HEIGHT = 400, LINES = 10;
	/**
	 * Mandatory serial version UID
	 */
	private static final long serialVersionUID = 1L;

	public ShowScore(Table scoreTable) {
		super("Highscore Table", null);
		
		int i;
		
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		myPanel = new JPanel(new GridLayout(LINES, 2));
		for (i = 0; i < LINES; ++i) {
			if (scoreTable.getName(i) == null) {
				myPanel.add(new JLabel(scoreTable.getName(i)));
				myPanel.add(new JLabel());
			} else {
				if (scoreTable.getName(i).length() > 8) {
					myPanel.add(new JLabel(scoreTable.getName(i).substring(1, 8)));
				} else 
					myPanel.add(new JLabel(scoreTable.getName(i)));
				if( new Integer(scoreTable.getScore(i)).toString().length() > 8) {
					myPanel.add(new JLabel(new Integer(scoreTable.getScore(i)).toString().substring(1, 8)) );
				} else
					myPanel.add(new JLabel(new Integer(scoreTable.getScore(i)).toString()) );
			}
		}
		
		this.setContentPane(myPanel);
		
		this.setSize(WIDTH, HEIGHT);
		setVisible(true);
	}
	
}
